package ar.com.personalTravellers.generators;

import ar.com.personalTravellers.beans.Neighborhood;
import ar.com.personalTravellers.generators.util.ResourcesDataGeneratorsUtil;
import ar.com.personalTravellers.rowProcessors.NeighborhoodRowProcessorCommand;
import ar.com.personalTravellers.spring.ApplicationContextSpring;
import com.angel.dao.generic.interfaces.GenericDAO;
import com.angel.data.generator.exceptions.DataGeneratorException;
import com.angel.data.generator.impl.ImportFileDataGenerator;
import com.angel.data.generator.interfaces.DataGenerator;
import com.angel.data.generator.util.StreamResourcesUtil;
import com.angel.io.descriptor.FileProcessorDescriptor;
import com.angel.io.processors.impl.ExcelFileProcessorCommand;
import com.angel.io.processors.log.ColumnSeparator;
import com.angel.io.processors.runner.impl.ImportFileProcessorRunner;

import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.Serializable;

/**
 *
 * @author William
 */
public class NeighborhoodFileDataGenerator extends ImportFileDataGenerator{

	private static final long serialVersionUID = 456392726459660147L;

	@SuppressWarnings("unchecked")
	public Class<? extends DataGenerator>[] getDependecesGenerators() {
        return (Class<? extends DataGenerator>[]) new Class[0];
    }

    public ImportFileProcessorRunner prepareImportFileProcessorRunner() {
		FileProcessorDescriptor descriptor = new FileProcessorDescriptor("Neirghborhood excel file", ColumnSeparator.COMMA);
		ImportFileProcessorRunner runner = new ImportFileProcessorRunner(descriptor,new ExcelFileProcessorCommand(), new NeighborhoodRowProcessorCommand());
        runner.addAliasFor(NeighborhoodRowProcessorCommand.NAME_COLUMN, "Nombre");
        runner.addAliasFor(NeighborhoodRowProcessorCommand.ZONE_COLUMN, "Zona");
        runner.addAliasFor(NeighborhoodRowProcessorCommand.ACTIVE_COLUMN, "Activo");
        return runner;
    }

    public InputStream prepareInputStream() {
        try {
            return StreamResourcesUtil.findInputStreamFor(ResourcesDataGeneratorsUtil.NEIGHBORHOOD_XLS_RESOURCE);
        } catch (FileNotFoundException e) {
            throw new DataGeneratorException("File not found [" + ResourcesDataGeneratorsUtil.NEIGHBORHOOD_XLS_RESOURCE + "].", e);
        }
    }

    public Class<? extends Object> getDataGeneratorClass() {
        return Neighborhood.class;
    }

    @SuppressWarnings("unchecked")
	public GenericDAO<Object, Serializable> getGenericDAO() {
        return (GenericDAO<Object, Serializable>) ApplicationContextSpring.createInstance().prepareApplicationContext().getBean("hotelDAO");
    }
}